package com.yq.homework.day22;

/**
 * @author 3307235355@qq.com
 * @since 2022/06/22 17:45
 */
public class Demo03 {
    public static void main(String[] args) {
        char[] c = new char[5];

        String[] s = new String[8];
        int start = '0';
        int end = 'z' + 1;
        String temp;

        for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < c.length; j++) {
                while (true) {
                    char c1 = (char) (Math.random() * (end - start) + start);
                    if (Character.isLetter(c1) || Character.isDigit(c1)) {
                        c[j] = c1;
                        break;
                    }
                }
            }
            String str = new String(c);
            s[i] = str;
        }

        for (int i = 0; i < s.length; i++) {
            System.out.println(s[i]);
        }
        System.out.println("-----排序完成------");

        for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s.length - i - 1; j++) {
                char fir = s[j].charAt(0);
                char sec = s[j + 1].charAt(0);
                if (Character.toLowerCase(fir) > Character.toLowerCase(sec)) {
                    temp = s[j];
                    s[j] = s[j + 1];
                    s[j + 1] = temp;
                }
            }
        }


        for (int i = 0; i < s.length; i++) {
            System.out.println(s[i]);
        }


    }
}
